//
//  BusinessLoginCtr.m
//  Traveling
//
//  Created by 曹秀云 on 15/6/13.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "BusinessLoginCtr.h"
#import "MineDataTool.h"

@interface BusinessLoginCtr ()
@property (weak, nonatomic) IBOutlet UITextField *userNameText;
@property (weak, nonatomic) IBOutlet UITextField *pwdText;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
@end

@implementation BusinessLoginCtr

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"商户登录"];
    [self.loginBtn addTarget:self action:@selector(LoginClick:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)LoginClick:(UIButton *)btn{
 
    NSString *username = self.userNameText.text;
    NSString *password = self.pwdText.text;
    
    if (ISBLANK(username))
    {
        [DialogUtils showTipsWithView:nil String:@"请填写登录账号！"];
        return;
    }
    
    
    if (!username.isValidatePhone)
    {
        [DialogUtils showTipsWithView:nil String:@"用户名不合法！"];
        return;
    }
    
    
    if (ISBLANK(password))
    {
        [DialogUtils showTipsWithView:nil String:@"请填写登录密码！"];
        return;
    }
    
    
    MBProgressHUD *loding = [DialogUtils showLoadingWithView:self.view];
    [MineDataTool loginWithUserName:username password:password loginType:personIdentityType success:^(RegisterResult *result) {
        [loding hide:YES];
        if(result.isSucc){
           [DefaultsHelper setInteger:companyIdentityType forKey:kCurrentIdentiryID];
            [result saveUserResult];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [DialogUtils showTipsWithView:nil String:result.msg];
        }
    } failure:^(NSError *error) {
        [loding hide:YES];
        [DialogUtils showTipsWithView:nil String:@"登陆失败"];
    }];
}

@end

